<?= $this->Html->script('locations.asset', array('inline'=>false)) ?>

<p>
	<?= $this->App->buttonLink('+ Nova Lokacija', '/locations/create') ?> |
	<?= $this->Html->link('Rezervacije', '/location_reservations') ?> |
	<?= $this->Html->link('Lista Lokacija', '/locations/lista') ?>
</p>

<?php
    $statuses = array(
        'free'     => 'Slobodne',
        'reserved' => 'Rezervisane',
        'occupied' => 'Zauzete'
    );
?>
<?= $this->Form->create('Search', array('url' => '/locations', 'class'=>'filter-form')) ?>
    <?= $this->Form->label('status', 'Status:') ?>
    <?= $this->Form->select('status', $statuses, array(
        'value' => @$filter['Search']['status'],
        'empty' => false
    )) ?>
    
    <?= $this->Form->label('from', 'Od:') ?>
    <?= $this->Form->text('from', array(
        'value' => @$filter['Search']['from'],
        'class' => 'datepicker'
    )) ?>
    <?= $this->Form->label('to', 'Do:', array('class'=>'inline')) ?>
    <?= $this->Form->text('to', array(
        'value' => @$filter['Search']['to'],
        'class' => 'datepicker'
    )) ?>
    
<?= $this->Form->submit('Traži', array('div'=>false)) ?>    
<?= $this->Form->submit('poništi', array(
    'type'    => 'button',
    'onclick' => "location.href='/locations'",
    'class'   => 'cancel',
    'div'     => false
)) ?>
<?= $this->Form->end() ?>

<?= $this->element('entity_table', array(
    'columns' => array(
        'Id'          => 'Location.id',
        'Naziv'       => 'Location.name',
        'Adresa'      => 'Location.address',
        'Tip Reklame' => array(false, function($row){
            $ret = array();
            foreach ($row['AdType'] as $adType) {
                $ret[] = $adType['name'];
            }
            return implode("<br>", $ret);
        }),
        'Status'      => array('Location.status', function($row) {
            $id = $row['Location']['id'];
            return '<span id="location-status-'.$id.'" class="status location-status" data-id="'.$id.'"></span>';
                    

                    /*'<a href="javascript:;" onclick="cancelStatus('.$id.')">cancel</a>'.
                   '</span>'.
                   '<script type="text/javascript">loadStatus('.$id.')</script>';*/
        }),
        'Cena'        => array(false, function($row){
            return currency_format($row['Location']['price'] + $row['Location']['rent_price']);
        })
    ),
    'columnWidth' => array(
        'Id'     => '1%',
        'Status' => '20%'
    ),
    'links'    => array(
        'Naziv'  => array('/locations/edit/%d', 'Location.id')
    ),
    'align'  => array(
        'Cena' => 'right'
    ),
    'filter' => array(
        
    ),
    'data'     => $locations,
    'id'       => 'Location.id',
    'entity'   => 'locations',
    'sort_by'  => $sort_by,
    'sort_dir' => $sort_dir,
    'actions'  => array(
        array(
            'label' => 'Kreiraj kampanju',
            'link'  => '/campaigns/create/?location=%s'
        ),
        array(
            'label' => 'Rezerviši',
            'link'  => '/location_reservations/create/?location=%s'
        )
    )
)) ?>